package com.example.localareanetworkchat.persistence.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import com.example.localareanetworkchat.persistence.entity.ChatGroup

@Dao
interface ChatGroupDao {

    @Insert
    fun insert(chatGroup: ChatGroup)

    @Query("select * from chat_group where user_id = :userId and dhcp_ip = :dhcpIp")
    fun queryAllByUserIdAndDhcp(userId: Long, dhcpIp: Int): LiveData<List<ChatGroup>>

    @Query("select * from chat_group where user_id = :userId")
    abstract fun queryAllByUserId(userId: Long): LiveData<List<ChatGroup>>?

    @Query("select * from chat_group where group_name = :groupName")
    fun queryByGroupName(groupName: String): ChatGroup

    @Query("select * from chat_group where group_invitation_code = :groupInvitationCode")
    fun queryByGroupInvitationCode(groupInvitationCode: String): ChatGroup

    @Query("select * from chat_group where chat_group_id = :chatGroupId")
    fun queryByChatGroupId(chatGroupId: String): ChatGroup

    @Query("delete from chat_group where uid = :uid and chat_group_id = :chatGroupId")
    fun deleteByUidAndChatGroupId(uid: String, chatGroupId: String)

}